;
; SYSLIB Module Name:  SEPSTR
; Author:  Richard Conn
; SYSLIB Version Number:  2.0
; Module Version Number:  1.0
; Module Entry Points:
;	EPSTR
; Module External References:
;	COUT
;

;
;  EPSTR -- 
;	PRINT STRING PTED TO BY HL
;	AFFECT ONLY HL -- WHEN DONE, HL PTS TO BYTE AFTER STRING
;	PERFORM NO CONTROL CHARACTER EXPANSION EXCEPT FOR <TAB>
;	INTERPRET <CR>, <LF>, <BEL>, <BS>
;
	EXT	COUT

EPSTR::
	PUSH	D	; SAVE REGS
	PUSH	B
	PUSH	PSW	; SAVE REG A AND FLAGS
	MVI	C,0	; SET POSITION COUNT
PSL:	MOV	A,M	; GET BYTE
	INX	H	; PT TO NEXT
	ORA	A	; 0=DONE
	JZ	PSD
	CPI	TAB	; EXPAND <TAB>
	JZ	PST
;  PRINT CHAR
	INR	C	; INCR POSITION
	CALL	COUT	; PRINT IT ON CON:
	CPI	CR	; CHECK FOR <CR>
	JZ	PCR
	CPI	LF	; CHECK FOR <LF>
	JZ	PLF
	CPI	BEL	; CHECK FOR <BEL>
	JZ	PLF
	CPI	BS	; CHECK FOR <BS>
	JZ	PBS
	JMP	PSL
;  <CR> -- RESET POSITION COUNT
PCR:	MVI	C,0	; RESET
	JMP	PSL
;  <LF>, <BEL>, <NULL> -- CURSOR DIDN'T ADVANCE
PLF:	DCR	C	; BACK UP COUNT BY 1
	JMP	PSL
;  <BS> -- CURSOR WENT BACKWARD, MAYBE
PBS:	MOV	A,C	; CHECK FOR ZERO
	ORA	A
	JZ	PSL
	DCR	C	; BACK UP COUNT BY 2
	DCR	C
	JMP	PSL
;  EXPAND <TAB>
PST:	MOV	A,C	; GET COUNT
	ANI	7	; MASK FOR SUB FROM 8
	MOV	B,A	; STORE TEMPORARILY
	MVI	A,8	; SUBTRACT FROM 8 FOR <SP> COUNT
	SUB	B
	MOV	B,A	; COUNT IN B
	ADD	C	; ADD TO POSITION COUNT
	MOV	C,A
	MVI	A,' '	; PRINT <SP>
PSTL:	CALL	COUT
	DCR	B	; COUNT DOWN
	JNZ	PSTL
	JMP	PSL
;  EPSTR DONE
PSD:	POP	PSW	; RESTORE REG A AND FLAGS
	POP	B	; RESTORE REGS
	POP	D
	RET

;
;  ASCII SPECIAL CHARACTER EQUATES
;
NULL	EQU	 0	; NULL
BEL	EQU	 7	; BELL
BS	EQU	 8	; BACKSPACE
TAB	EQU	 9	; TAB
LF	EQU	10	; LINE FEED
CR	EQU	13	; CARRIAGE RETURN
CTRLR	EQU	'R'-40H	; CTRL-R
CTRLU	EQU	'U'-40H	; CTRL-U
CTRLX	EQU	'X'-40H	; CTRL-X
DEL	EQU	7FH	; DELETE CHAR

	END
